import NProgress from 'nprogress';
import router from '@/router';
import store from '@/store';
import { METAINFO_ACTION } from '@/utils/Const';
import { getlocalIpApi } from '@/api/common.api';

NProgress.inc(0.2);
NProgress.configure({ easing: 'ease', speed: 500, showSpinner: false });
router.beforeEach(async (to: any, from, next) => {
	if (!window['localIp']) {
		let { ip }: any = await getlocalIpApi();
		window['localIp'] = ip;
	}
	NProgress.start();
	document.title = (to.meta && to.meta.title) || '低代码编辑器';
	store.dispatch(`metaInfo/${METAINFO_ACTION}`, to.meta);
	next();
});

router.afterEach((to: any) => {
	NProgress.done();
});
